<?php
/************************************
*   熊店
*   @file:/server/bearshop/index.php
*   @intro:
*   @author:new_shop
*   @email:new_shop@163.com    
*   @date:Thu Feb 11 18:01:30 CST 2010
************************************/
include('__global.php');
//简单路由器
list($uri) = explode('?' , trim($_SERVER['REQUEST_URI'],'/'));
$a_param = explode('/' , $uri);
$first = array_shift($a_param);

if($first == 'api')
{
    $api_name = array_shift($a_param);
    $file_name = K5_ROOT.'/api/'.$api_name.'.php';

    if(!is_file($file_name))
    {
        die('404');
    }
    
    include($file_name);
    
    $class = $api_name;
    new $class($a_param);
}
else
{
    $sub_dir = '';
    
    if($first == '')
        $first = 'index';
    if(is_dir(K5_ROOT.'/page/'.$first))
    {
        $sub_dir = $first.'/';
        $page_name = array_shift($a_param);
        if(!$page_name)
            $page_name = 'index';
    }
    else 
    {
        $page_name = $first;
    }
    
    $file_name = K5_ROOT.'/page/'.$sub_dir.'p_'.$page_name.'.php';

    if(!is_file($file_name))
    {
        $page_name = '404';
        $file_name = K5_ROOT.'/page/p_404.php';
    }
    
    include($file_name);
    
    $class = 'p_'.$page_name;
    new $class($a_param);
}
?>
